package com.hirisun.calendar.filter;

import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;

import com.hirisun.calendar.util.ChineseDate;

public class ChineseFestivalFilter extends FestivalFilterBase {

	public boolean isVocation(Date date) {

		long[] chineseDate = getChineseDate(date);

		for (Iterator<FestivalDay> iterator = festivals.iterator(); iterator
				.hasNext();) {
			FestivalDay festival = (FestivalDay) iterator.next();

			if (isVocation(chineseDate, festival)) {
				return true;
			}

		}
		return false;
	}

	private boolean isVocation(long[] chineseDate, FestivalDay festival) {
		if (chineseDate[1] == festival.getMonth()
				&& chineseDate[2] == festival.getDay()) {
			return true;
		}
		return false;
	}

	private long[] getChineseDate(Date date) {
		
		Calendar today = Calendar.getInstance(Locale.SIMPLIFIED_CHINESE);
		today.setTime(date);
		int year = today.get(Calendar.YEAR);
		int month = today.get(Calendar.MONTH) + 1;
		int day = today.get(Calendar.DATE);
		long[] chineseDate = ChineseDate.calElement(year, month, day);
		return chineseDate;
	}

}
